﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpCmd.Controls;
using SharpCmd.IO;

namespace SharpCmd.Dialogs.PanelActions
{
    internal partial class DeletePrepareForm : Form
    {
        private const string LabelInfoFormatString = "Really delete the {0} selected items?";

        public DeletePrepareForm()
        {
            InitializeComponent();
            this.Icon = MainForm.Instance.Icon;
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            listView1.SmallImageList = ImageLists.FileDirectoryList;
        }

        public List<FSObjectInfo> Infos { get; set; }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (msg.Msg)
            {
                case Windows.Events.WM_KEYDOWN:
                    Keys keyCode = (Keys)msg.WParam;
                    if (keyCode == Keys.Escape)
                    {
                        Close();
                        return true;
                    }
                    else if (keyCode == Keys.Enter)
                    {
                        DialogResult = System.Windows.Forms.DialogResult.OK;
                        Close();
                        return true;
                    }
                    break;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void DeletePrepareForm_Shown(object sender, EventArgs e)
        {
            labelInfo.Text = string.Format(LabelInfoFormatString, Infos.Count);
            //load listview
            listView1.BeginUpdate();
            foreach (var info in Infos)
            {
                listView1.Items.Add(new ListViewItem(info.Name, info.Type == FSObjectType.File ? ImageLists.FILEDIRECTORY_FILE : ImageLists.FILEDIRECTORY_DIRECTORY));
            }
            listView1.EndUpdate();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
    }
}